package cn.edu.hunau.basic.day03;

import org.junit.Test;

import java.util.Random;
import java.util.Scanner;

/**
 * @author hb
 * @date 2025-07-30 09:27:59
 */
public class GuessNumberTest {

    @Test
    public void test(){
        //1. 获得一个1-100之间的随机数
        Random r=new Random();
        int num = r.nextInt(100) + 1;
        Scanner sc=new Scanner(System.in);
        int count =0;//记录用户猜的次数
        System.out.println(num);
        while(true){
            count++;
            //获得用户输入的信息
            System.out.print("请输入猜的数字：");
            int i = sc.nextInt();
            if(i>num){
                System.out.println("猜的数字太大了");
            }else if(i<num){
                System.out.println("猜的数字太小了");
            }else{
                System.out.println("恭喜你猜对了,一共猜了"+count+"次");
                break;
            }
        }
    }
}
